package com.wc.acwing.前缀和与差分.商品库存管理;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/4/3 22:00
 * @description
 * https://www.acwing.com/problem/content/5997/
 */
public class Main {
    /**
     * 思路：
     * 只需要记录区间内 1的个数即可, 然后记录原始 0 的个数, 加起来就是未操作 i 的 0 的个数
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 300010;
    static int[] d = new int[N], ones = new int[N];
    static int[] L = new int[N], R = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            d[r + 1] -= 1;
            d[l] += 1;
            L[i] = l;
            R[i] = r;
        }
        for (int i = 1; i <= n; i++) d[i] += d[i - 1];
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            if (d[i] == 1) ones[i] += 1;
            ones[i] += ones[i - 1];
            if (d[i] == 0) cnt++;
        }
        for (int i = 1; i <= m; i++) {
            int l = L[i], r = R[i];
            int sum = ones[r] - ones[l - 1];
            out.println(cnt + sum);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

